package com.example.zhinongbao.ui;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.zhinongbao.R;
import com.example.zhinongbao.adapter.ContactAdapter;
import com.example.zhinongbao.bean.Contact;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 消息页面
 */
public class MessageFragment extends Fragment {
    // 联系人列表
    private final List<Contact> contactList = new ArrayList<>();
    // 联系人适配器
    private ContactAdapter contactAdapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_message, container, false);
    }

    @Override
    public void onResume() {
        super.onResume();
        initView();
    }

    private void initView() {
        RecyclerView message_recycler_view = getView().findViewById(R.id.message_recycler_view);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
        message_recycler_view.setLayoutManager(linearLayoutManager);
        contactAdapter = new ContactAdapter(contactList);
        message_recycler_view.setAdapter(contactAdapter);
        initData();
    }

    /**
     * 初始化联系人数据
     */
    private void initData() {
        contactList.clear();
        contactList.add(new Contact("路人甲", "你好啊", new Date()));
        contactList.add(new Contact("路人乙", "啥时候发货啊", new Date()));
        contactAdapter.notifyDataSetChanged();
    }
}
